package {
	import com.greensock.TweenMax;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	import org.osflash.signals.Signal;

	public class EndCircle extends Circle {
		
		public var postFB:Signal;
		public var postTwitter:Signal;
		public var mainMenu:Signal;
		
		public function EndCircle(view:MovieClip) {
			super(view);
			view.buttonMode = false;
			view.mouseChildren = true;
			
			postFB = new Signal();
			postTwitter = new Signal();
			mainMenu = new Signal();
			createButton(view.mainMenuBtn, "Main Menu");
			view.fbBtn.buttonMode = view.twitterBtn.buttonMode = true;
			view.fbBtn.addEventListener(MouseEvent.MOUSE_DOWN, onFB);
			view.twitterBtn.addEventListener(MouseEvent.MOUSE_DOWN, onTwitter);
			view.mainMenuBtn.addEventListener(MouseEvent.MOUSE_DOWN, onMainMenu);
		}
		
		public function set time(val:String):void {
			view.time.autoSize = "center";
			view.time.text = val;
		}
		
		private function onFB(e:MouseEvent):void {
			postFB.dispatch();
		}
		
		private function onTwitter(e:MouseEvent):void {
			postTwitter.dispatch();	
		}
		
		private function onMainMenu(e:MouseEvent):void {
			mainMenu.dispatch();	
		}
		
		private function createButton(m:MovieClip, label:String):MovieClip {
			m.addEventListener(MouseEvent.ROLL_OVER, onMenuButton);
			m.addEventListener(MouseEvent.ROLL_OUT, onMenuButton);
			m.buttonMode = true;
			m.mouseChildren = false;
			m.txt.autoSize = "center";
			m.txt.text = label;
			return m;
		}
		
		private function onMenuButton(e:MouseEvent):void {
			switch(e.type) {
				case MouseEvent.ROLL_OVER :
					TweenMax.to(e.currentTarget, .2, {tint:0xFFFFFF, scaleX:1.1, scaleY:1.1});
					break;
				
				case MouseEvent.ROLL_OUT :
					TweenMax.to(e.currentTarget, .2, {tint:0x000000, scaleX:1, scaleY:1});
					break;
			}
		}
		
		
		
	}
}